package com.vipboot.framework.sms.autoconfig;

import com.vipboot.framework.sms.dao.SmsDaoRedisImpl;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.api.dao.SmsDao;
import org.redisson.client.RedisClient;
import org.redisson.spring.starter.RedissonAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

@Slf4j
@AutoConfiguration
public class SmsAutoConfig {

    /**
     * 自定义持久层实现-Redis（默认）
     */
//    @ConditionalOnMissingBean(SaTokenDao.class)
    @ConditionalOnClass(RedisClient.class)
    @AutoConfigureAfter(RedissonAutoConfiguration.class)
    @ConditionalOnProperty(name = "sms.extension.dao.type", havingValue = "redis")
    public static class Redis {
        static {
            log.info("初始化 SmsAutoConfiguration 'Sms-Dao-Redis'");
        }

        @Primary
        @Bean
        public SmsDao smsDao() {
            return new SmsDaoRedisImpl();
        }
    }

//    @Primary
//    @Bean
//    public SmsDao smsDao() {
//        return new PlusSmsDao();
//    }

}
